package novel.front.novellist.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import novel.common.constant.IConstInfo;
import novel.common.enums.CategoryType;
import novel.common.enums.TagType;
import novel.common.page.PageInfo;
import novel.common.page.PageParam;
import novel.common.utils.HttpClientUtil;
import novel.common.utils.JsonUtil;
import novel.common.utils.string.StringUntils;
import novel.common.web.BaseController;
import novel.front.novellist.dao.AppsoMapper;
import novel.front.novellist.dao.KuaixunMapper;
import novel.front.novellist.dao.LiebaoAppMapper;
import novel.front.novellist.entity.Appso;
import novel.front.novellist.entity.Kuaixun;
import novel.front.novellist.entity.LiebaoApp;
import novel.front.novellist.service.AppAsyncService;
import novel.front.novellist.service.KuaixunService;
import novel.front.novellist.service.LiebaoAppService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.util.HtmlUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by 888 on 2017/2/8.
 */
@Controller
@RequestMapping("")
public class WxAppController extends BaseController {

    @Resource
    private LiebaoAppService liebaoAppService;

    @Resource
    private AppAsyncService appAsyncService;

    @Resource
    private KuaixunService kuaixunService;

    @Resource
    private KuaixunMapper kuaixunMapper;

    @Resource
    private LiebaoAppMapper liebaoAppMapper;

    @Resource
    private AppsoMapper appsoMapper;

    @RequestMapping(value = "index")
    public String home(ModelMap modelMap, HttpServletRequest request) {
        //最新发布
        List<LiebaoApp> zxfbList = liebaoAppService.getListDesc(0, 18);
        //热门推荐8
        LiebaoApp liebaoApp = new LiebaoApp();
        liebaoApp.setIsCheck(IConstInfo.CHECKED);
        liebaoApp.setHomeType(1);
        List<LiebaoApp> rmtjList = liebaoAppService.searchApp(liebaoApp, IConstInfo.HOME_TYPE_RMTJ);
        //精挑细选8
        liebaoApp.setHomeType(2);
        List<LiebaoApp> jtxxList = liebaoAppService.searchApp(liebaoApp, IConstInfo.HOME_TYPE_JTXX);
        //实用工具16
        liebaoApp.setHomeType(4);
        List<LiebaoApp> sygjList = liebaoAppService.searchApp(liebaoApp, IConstInfo.HOME_TYPE_SYGJ);
        //电商购物16
        liebaoApp.setHomeType(5);
        List<LiebaoApp> dsgwList = liebaoAppService.searchApp(liebaoApp, IConstInfo.HOME_TYPE_DSGW);
        //旅游出行16
        liebaoApp.setHomeType(6);
        List<LiebaoApp> lycxList = liebaoAppService.searchApp(liebaoApp, IConstInfo.HOME_TYPE_LYCX);
        //居家生活16
        liebaoApp.setHomeType(7);
        List<LiebaoApp> jjshList = liebaoAppService.searchApp(liebaoApp, IConstInfo.HOME_TYPE_JJSH);
        //社交娱乐16
        LiebaoApp sjcx = new LiebaoApp();
        sjcx.setHomeType(8);
        List<LiebaoApp> sjcxList = liebaoAppService.searchApp(sjcx, IConstInfo.HOME_TYPE_SJCX);
        modelMap.addAttribute("zxfbList", zxfbList);
        modelMap.addAttribute("rmtjList", rmtjList);
        modelMap.addAttribute("jtxxList", jtxxList);
        modelMap.addAttribute("sygjList", sygjList);
        modelMap.addAttribute("dsgwList", dsgwList);
        modelMap.addAttribute("lycxList", lycxList);
        modelMap.addAttribute("jjshList", jjshList);
        modelMap.addAttribute("sjcxList", sjcxList);

        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        //modelMap.addAttribute("seoTitle","微信小程序大全 - 微信小程序推荐 - 小程序商店");
        modelMap.addAttribute("seoTitle", "微信小程序大全 - 小程序商店 - 【免费】收录优秀微信小程序 - 小程序游戏");
        modelMap.addAttribute("seoKeywords", "微信小程序,微信小程序有哪些,小程序推广,小程序收录");
        modelMap.addAttribute("seoDescription", "全网首家小程序商店收录海量精选小程序，收录最新、最好玩、最热门、最实用的微信小程序，集小程序资讯、小程序游戏、小程序推荐、小程序推广为一体的综合性小程序门户网站，帮助优质小程序有效触达用户，为用户提供更好的小程序体验。");
        return "app/home";
    }

    /**
     * 最新
     *
     * @return
     */
    @RequestMapping(value = "/newAppList", method = RequestMethod.GET)
    public String newAppList(ModelMap modelMap) {
        List<LiebaoApp> liebaoAppList = liebaoAppService.getListDesc(0, 45);
        modelMap.addAttribute("liebaoAppList", liebaoAppList);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        modelMap.addAttribute("seoTitle", "最新小程序有哪些 -  最新小程序哪个好 - 最新类微信小程序微信大全 - 小程序大全");
        modelMap.addAttribute("seoKeywords", "最新小程序有哪些 ,最新小程序哪个好,最新小程序二维码");
        modelMap.addAttribute("seoDescription", "酷酷屋小程序商店最新频道，收录了最新、最好玩、最热门、最优质、最实用的最新类小程序，提供最新小程序的最新信息、截图及二维码。更多小程序请访问kukuwu.com");
        return "app/appList";
    }

    /**
     * 热门推荐
     *
     * @return
     */
    @RequestMapping(value = "/hotAppList", method = RequestMethod.GET)
    public String hotAppList(ModelMap modelMap) {
        List<LiebaoApp> liebaoAppList = liebaoAppService.getListRandom();
        modelMap.addAttribute("liebaoAppList", liebaoAppList);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        modelMap.addAttribute("seoTitle", "热门优秀小程序 - 小程序大全");
        modelMap.addAttribute("seoKeywords", "热门优秀小程序有哪些 ,热门优秀小程序哪个好,热门优秀小程序二维码");
        modelMap.addAttribute("seoDescription", "酷酷屋小程序商店最新频道，收录了最新、最好玩、最热门、最优质、最实用的热门优秀小程序类小程序，提供热门优秀小程序小程序的最新信息、截图及二维码。更多小程序请访问kukuwu.com");
        return "app/appList";
    }

    /**
     * 荆条西选
     *
     * @return
     */
    @RequestMapping(value = "/jtxxAppList", method = RequestMethod.GET)
    public String jtxxAppList(ModelMap modelMap) {
        List<LiebaoApp> liebaoAppList = liebaoAppService.getListRandom();
        modelMap.addAttribute("liebaoAppList", liebaoAppList);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        modelMap.addAttribute("seoTitle", "实在小程序推荐 - 小程序大全");
        modelMap.addAttribute("seoKeywords", "热实在小程序推荐");
        modelMap.addAttribute("seoDescription", "实在小程序推荐。更多小程序请访问kukuwu.com");
        return "app/appList";
    }

    /**
     * 实用工具
     *
     * @return
     */
    @RequestMapping(value = "/toolAppList", method = RequestMethod.GET)
    public String toolAppList(ModelMap modelMap) {
        String categoryName = CategoryType.getName(9);
        LiebaoApp liebaoApp = new LiebaoApp();
        liebaoApp.setAppName(categoryName);
        liebaoApp.setTagsArr(categoryName);
        List<LiebaoApp> liebaoAppList = liebaoAppService.searchApp(liebaoApp, "");
        modelMap.addAttribute("liebaoAppList", liebaoAppList);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        modelMap.addAttribute("seoTitle", "实用工具类小程序 - 小程序大全");
        modelMap.addAttribute("seoKeywords", "实用工具类小程序");
        modelMap.addAttribute("seoDescription", "实用工具类小程序。更多小程序请访问kukuwu.com");
        return "app/appList";
    }

    /**
     * 电商购物
     *
     * @return
     */
    @RequestMapping(value = "/shopAppList", method = RequestMethod.GET)
    public String shopAppList(ModelMap modelMap) {
        String categoryName = CategoryType.getName(6);
        LiebaoApp liebaoApp = new LiebaoApp();
        liebaoApp.setAppName(categoryName);
        liebaoApp.setTagsArr(categoryName);
        List<LiebaoApp> liebaoAppList = liebaoAppService.searchApp(liebaoApp, "");
        modelMap.addAttribute("liebaoAppList", liebaoAppList);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        modelMap.addAttribute("seoTitle", "电商类小程序 - 小程序大全");
        modelMap.addAttribute("seoKeywords", "电商类小程序");
        modelMap.addAttribute("seoDescription", "电商类小程序。更多小程序请访问kukuwu.com");
        return "app/appList";
    }

    /**
     * 旅游出行
     *
     * @return
     */
    @RequestMapping(value = "/tourAppList", method = RequestMethod.GET)
    public String tourAppList(ModelMap modelMap) {
        String categoryName = CategoryType.getName(6);
        LiebaoApp liebaoApp = new LiebaoApp();
        liebaoApp.setAppName(categoryName);
        liebaoApp.setTagsArr(categoryName);
        List<LiebaoApp> liebaoAppList = liebaoAppService.searchApp(liebaoApp, "");
        modelMap.addAttribute("liebaoAppList", liebaoAppList);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        modelMap.addAttribute("seoTitle", "旅游类小程序 - 小程序大全");
        modelMap.addAttribute("seoKeywords", "旅游类小程序");
        modelMap.addAttribute("seoDescription", "旅游类小程序。更多小程序请访问kukuwu.com");
        return "app/appList";
    }

    /**
     * 居家生活
     *
     * @return
     */
    @RequestMapping(value = "/liveAppList", method = RequestMethod.GET)
    public String liveAppList(ModelMap modelMap) {
        String categoryName = CategoryType.getName(12);
        LiebaoApp liebaoApp = new LiebaoApp();
        liebaoApp.setAppName(categoryName);
        liebaoApp.setTagsArr(categoryName);
        List<LiebaoApp> liebaoAppList = liebaoAppService.searchApp(liebaoApp, "");
        modelMap.addAttribute("liebaoAppList", liebaoAppList);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        modelMap.addAttribute("seoTitle", "生活类小程序 - 小程序大全");
        modelMap.addAttribute("seoKeywords", "生活类小程序");
        modelMap.addAttribute("seoDescription", "生活类小程序。更多小程序请访问kukuwu.com");
        return "app/appList";
    }

    /**
     * 社交
     *
     * @return
     */
    @RequestMapping(value = "/socialAppList", method = RequestMethod.GET)
    public String socialAppList(ModelMap modelMap) {
        String categoryName = CategoryType.getName(15);
        LiebaoApp liebaoApp = new LiebaoApp();
        liebaoApp.setAppName(categoryName);
        liebaoApp.setTagsArr(categoryName);
        List<LiebaoApp> liebaoAppList = liebaoAppService.searchApp(liebaoApp, "");
        modelMap.addAttribute("liebaoAppList", liebaoAppList);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        modelMap.addAttribute("seoTitle", "社交类小程序 - 小程序大全");
        modelMap.addAttribute("seoKeywords", "社交类小程序");
        modelMap.addAttribute("seoDescription", "社交类小程序。更多小程序请访问kukuwu.com");
        return "app/appList";
    }

    /**
     * 列表
     *
     * @param modelMap
     * @param
     * @return
     */
    @RequestMapping(value = "/tag/{tagsArr}", method = RequestMethod.GET)
    public String wxAppList(ModelMap modelMap, @PathVariable String tagsArr, HttpServletRequest request) {
        modelMap.addAttribute("para", tagsArr);
        if (StringUntils.isNumber(tagsArr)) {
            tagsArr = TagType.getName(Integer.parseInt(tagsArr));
        }
        LiebaoApp liebaoApp = new LiebaoApp();
        liebaoApp.setTagsArr(tagsArr);
        liebaoApp.setIsCheck(IConstInfo.CHECKED);
        PageParam pageParam = this.getPageParam(request);
        pageParam.setPageNum(1);
        pageParam.setPageSize(100);
        PageInfo<LiebaoApp> pageInfo = liebaoAppService.getListByPage(liebaoApp, pageParam);
        modelMap.addAttribute("pageInfo", pageInfo);
        modelMap.addAttribute("liebaoApp", liebaoApp);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        modelMap.addAttribute("seoTitle", liebaoApp.getTagsArr() + "类小程序有哪些 - " + liebaoApp.getTagsArr() + "类小程序哪个好 - " + liebaoApp.getTagsArr() + "类微信小程序微信大全 - 小程序大全");
        modelMap.addAttribute("seoKeywords", liebaoApp.getTagsArr() + "小程序有哪些 ," + liebaoApp.getTagsArr() + "小程序哪个好," + liebaoApp.getTagsArr() + "小程序二维码");
        modelMap.addAttribute("seoDescription", "酷酷屋小程序商店" + liebaoApp.getTagsArr() + "频道，收录了最新、最好玩、最热门、最优质、最实用的" + liebaoApp.getTagsArr() + "类小程序，提供" + liebaoApp.getTagsArr() + "小程序的最新信息、截图及二维码。更多小程序请访问kukuwu.com");
        return "app/appList";
    }

    /**
     * 搜索
     *
     * @param modelMap
     * @param
     * @return
     */
    @RequestMapping(value = "/app/search", method = RequestMethod.POST)
    public String search(ModelMap modelMap, HttpServletRequest request) {
        String tagsArr = request.getParameter("appName");
        if (tagsArr != null && tagsArr.trim() != "") {
            LiebaoApp liebaoApp = new LiebaoApp();
            liebaoApp.setAppName(tagsArr);
            liebaoApp.setTagsArr(tagsArr);
            liebaoApp.setIsCheck(IConstInfo.CHECKED);
            PageParam pageParam = this.getPageParam(request);
            pageParam.setPageNum(1);
            pageParam.setPageSize(100);
            PageInfo<LiebaoApp> pageInfo = liebaoAppService.getListByPage(liebaoApp, pageParam);
            modelMap.addAttribute("pageInfo", pageInfo);
            modelMap.addAttribute("liebaoApp", liebaoApp);
            modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        }
        modelMap.addAttribute("para", tagsArr);
        //seo
        modelMap.addAttribute("seoTitle", tagsArr + "小程序有哪些 - " + tagsArr + "小程序哪个好 - " + tagsArr + "类微信小程序微信大全 - 小程序大全");
        modelMap.addAttribute("seoKeywords", tagsArr + "小程序有哪些 ," + tagsArr + "小程序哪个好," + tagsArr + "小程序二维码");
        modelMap.addAttribute("seoDescription", "酷酷屋小程序商店" + tagsArr + "频道，收录了最新、最好玩、最热门、最优质、最实用的" + tagsArr + "类小程序，提供" + tagsArr + "小程序的最新信息、截图及二维码。更多小程序请访问kukuwu.com");
        return "app/appList";
    }

    /**
     * 分类列表
     *
     * @param modelMap
     * @param
     * @return
     */
    @RequestMapping(value = "/category/{categoryId}", method = RequestMethod.GET)
    public String categoryList(ModelMap modelMap, @PathVariable Integer categoryId, HttpServletRequest request) {
        String categoryName = CategoryType.getName(categoryId);
//    List<LiebaoApp> liebaoAppList = liebaoAppService.getListByCategoryId(categoryId);
        LiebaoApp liebaoApp = new LiebaoApp();
        liebaoApp.setAppName(categoryName);
        liebaoApp.setTagsArr(categoryName);
        liebaoApp.setCategoryId(categoryId);
        PageParam pageParam = this.getPageParam(request);
        pageParam.setPageNum(1);
//    List<LiebaoApp> liebaoAppList = liebaoAppService.searchApp(liebaoApp,"");
        PageInfo<LiebaoApp> pageInfo = liebaoAppService.getListByPage(liebaoApp, pageParam);
//    modelMap.addAttribute("liebaoAppList", liebaoAppList);
        modelMap.addAttribute("para", categoryId.toString());
//    modelMap.addAttribute("liebaoApp", liebaoApp);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        modelMap.addAttribute("pageInfo", pageInfo);
        modelMap.addAttribute("pageInfoStr", pageInfo);
        //seo
        modelMap.addAttribute("seoTitle", categoryName + "小程序有哪些 - " + categoryName + "小程序哪个好 - " + categoryName + "类微信小程序微信大全 - 小程序大全");
        modelMap.addAttribute("seoKeywords", categoryName + "小程序有哪些 ," + categoryName + "小程序哪个好," + categoryName + "小程序二维码");
        modelMap.addAttribute("seoDescription", "酷酷屋小程序商店" + categoryName + "频道，收录了最新、最好玩、最热门、最优质、最实用的" + categoryName + "类小程序，提供" + categoryName + "小程序的最新信息、截图及二维码。更多小程序请访问kukuwu.com");
        return "app/appList";
    }

    /**
     * 分类列表分页
     *
     * @param modelMap
     * @param
     * @return
     */
    @RequestMapping(value = "/categoryc/{categoryId}/{pageNume}", method = RequestMethod.GET)
    public String categoryList1(ModelMap modelMap, @PathVariable Integer categoryId, @PathVariable Integer pageNume, HttpServletRequest request) {
        String categoryName = CategoryType.getName(categoryId);
//    List<LiebaoApp> liebaoAppList = liebaoAppService.getListByCategoryId(categoryId);
        LiebaoApp liebaoApp = new LiebaoApp();
        liebaoApp.setAppName(categoryName);
        liebaoApp.setTagsArr(categoryName);
        liebaoApp.setCategoryId(categoryId);
        PageParam pageParam = this.getPageParam(request);
        pageParam.setPageNum(pageNume);
//    List<LiebaoApp> liebaoAppList = liebaoAppService.searchApp(liebaoApp,"");
        PageInfo<LiebaoApp> pageInfo = liebaoAppService.getListByPage(liebaoApp, pageParam);
//    modelMap.addAttribute("liebaoAppList", liebaoAppList);
        modelMap.addAttribute("para", categoryId.toString());
//    modelMap.addAttribute("liebaoApp", liebaoApp);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        modelMap.addAttribute("pageInfo", pageInfo);
        //seo
        modelMap.addAttribute("seoTitle", categoryName + "小程序有哪些 - " + categoryName + "小程序哪个好 - " + categoryName + "类微信小程序微信大全 - 小程序大全");
        modelMap.addAttribute("seoKeywords", categoryName + "小程序有哪些 ," + categoryName + "小程序哪个好," + categoryName + "小程序二维码");
        modelMap.addAttribute("seoDescription", "酷酷屋小程序商店" + categoryName + "频道，收录了最新、最好玩、最热门、最优质、最实用的" + categoryName + "类小程序，提供" + categoryName + "小程序的最新信息、截图及二维码。更多小程序请访问kukuwu.com");
        return "app/appList";
    }

    @RequestMapping(value = "wxApp/{pageNume}", method = RequestMethod.GET)
    public String wxAppAll(ModelMap modelMap, LiebaoApp liebaoApp, @PathVariable int pageNume, HttpServletRequest request) {
        PageParam pageParam = this.getPageParam(request);
        pageParam.setPageNum(pageNume);
        liebaoApp.setIsCheck(IConstInfo.CHECKED);
        PageInfo<LiebaoApp> pageInfo = liebaoAppService.getListByPage(liebaoApp, pageParam);
        modelMap.addAttribute("pageInfo", pageInfo);
        modelMap.addAttribute("pageParam", pageParam);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        modelMap.addAttribute("seoTitle", "小程序精选 - 做的比较好的小程序 - 小程序大全");
        modelMap.addAttribute("seoKeywords", "小程序精选 ,做的比较好的小程序,好玩的小程序");
        modelMap.addAttribute("seoDescription", "酷酷屋小程序商店频道，收录了最新、最好玩、最热门、最优质、最实用的小程序的最新信息、截图及二维码。更多小程序请访问kukuwu.com");
        return "app/category";
    }

    /**
     * 下拉分页
     *
     * @param modelMap
     * @param liebaoApp
     * @param request
     * @return
     */
    @RequestMapping(value = "/home", method = RequestMethod.GET)
    public String index(ModelMap modelMap, LiebaoApp liebaoApp, HttpServletRequest request) {
        //seo
        modelMap.addAttribute("seoTitle", "酷酷屋微信小程序大全 - 小程序商店_【免费】收录优秀微信小程序 - 小程序大全");
        modelMap.addAttribute("seoKeywords", "小程序商店,小程序精选,小程序排名,微信小程序,小程序市场");
        modelMap.addAttribute("seoDescription", "酷酷屋小程序官方商店收录最新、最好玩、最热门、最实用的微信小程序，是国内首家集小程序资讯、小程序导航、小程序推荐、小程序推广为一体的综合性小程序门户网站。");
        return "app/index";
    }

    /**
     * 添加
     *
     * @param modelMap
     * @return
     */
    @RequestMapping(value = "publish")
    public String publish(ModelMap modelMap, HttpServletRequest request) {
        String id = request.getParameter("id");
        String user = request.getParameter("user");
        LiebaoApp liebaoApp = null;
        if (StringUntils.isNotEmpty(id)) {
            liebaoApp = liebaoAppService.selectByPrimaryKey(Integer.parseInt(id));
        }
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        modelMap.addAttribute("app", liebaoApp);
        modelMap.addAttribute("user", user);
        modelMap.addAttribute("seoTitle", "免费收录小程序 - 小程序推广 - 小程序大全");
        modelMap.addAttribute("seoKeywords", "免费收录小程序,小程序推广");
        modelMap.addAttribute("seoDescription", "酷酷屋腾讯小程序大全官网免费收录小程序，免费帮您推广微信小程序kukuwu.com");
        return "app/publish";
    }

    @RequestMapping(value = "saveApp")
    @ResponseBody
    public boolean saveApp(LiebaoApp liebaoApp, HttpServletRequest request) {
        String id = request.getParameter("id");
        liebaoApp.setAppDesc(HtmlUtils.htmlUnescape(liebaoApp.getAppDesc()));
        liebaoApp.setAppUpdate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
//        liebaoApp.setAppName(liebaoApp.getName().replace(",",""));
        if (StringUntils.isNotEmpty(id)) {
            liebaoAppService.update(liebaoApp);
        } else {
            liebaoAppService.save(liebaoApp);
        }
        return true;
    }

    @RequestMapping(value = "check")
    public String check(LiebaoApp liebaoApp) {
//        liebaoAppService.update(liebaoApp);
        appAsyncService.setHomeTypeRedis();//输出1
        System.out.println("2");
        return "";
    }

    /**
     * 審核列表
     *
     * @param modelMap
     * @param
     * @return
     */
    @RequestMapping(value = "/checkList", method = RequestMethod.GET)
    public String wxCheckList(ModelMap modelMap) {
        LiebaoApp liebaoApp = new LiebaoApp();
        liebaoApp.setIsCheck(IConstInfo.NOT_CHECK);
        List<LiebaoApp> liebaoAppList = liebaoAppService.getList(liebaoApp);
        modelMap.addAttribute("liebaoAppList", liebaoAppList);
        return "app/checkList";
    }

    @RequestMapping(value = "analysisUI")
    public String analysis(ModelMap modelMap) {
        //seo
        modelMap.addAttribute("seoTitle", "各行业小程序数量占比");
        modelMap.addAttribute("seoKeywords", "微信小程序,微信小程序数量,各行业小程序占比");
        modelMap.addAttribute("seoDescription", "小程序行业市场现状及发展趋势");
        return "app/analysisUI";
    }

    @RequestMapping(value = "getTageData", method = RequestMethod.GET)
    @ResponseBody
    public String getTageData() {
//        if (JedisUtil.exists("tageData") && StringUntils.isNotEmpty(JedisUtil.get("tageData", String.class))) {
//            System.out.println("redis输出");
//            return JedisUtil.get("tageData");
//        }
//        List<Map<String, String>> mapList = liebaoAppService.getTagPercent();
//        String jsonString = JSON.toJSONString(mapList);
//        JedisUtil.set("tageData", jsonString);
//        System.out.println("DB输出");
//        return jsonString;
        String json = "[{\"num\":16,\"tag\":\" \"},{\"num\":15,\"tag\":\" 交通\"},{\"num\":2,\"tag\":\" 体育\"},{\"num\":5,\"tag\":\" 健康医疗\"},{\"num\":1,\"tag\":\" 图片\"},{\"num\":17,\"tag\":\" 娱乐\"},{\"num\":40,\"tag\":\" 工具\"},{\"num\":12,\"tag\":\" 房地产\"},{\"num\":29,\"tag\":\" 投资理财\"},{\"num\":20,\"tag\":\" 教育\"},{\"num\":2,\"tag\":\" 教育培训\"},{\"num\":4,\"tag\":\" 新闻\"},{\"num\":4,\"tag\":\" 旅游\"},{\"num\":6,\"tag\":\" 旅行\"},{\"num\":65,\"tag\":\" 查询\"},{\"num\":5,\"tag\":\" 汽车\"},{\"num\":37,\"tag\":\" 生活\"},{\"num\":1,\"tag\":\" 生活服务\"},{\"num\":5,\"tag\":\" 电台\"},{\"num\":1,\"tag\":\" 电商\"},{\"num\":17,\"tag\":\" 社区\"},{\"num\":15,\"tag\":\" 美图\"},{\"num\":2,\"tag\":\" 美妆\"},{\"num\":6,\"tag\":\" 美食\"},{\"num\":15,\"tag\":\" 自媒体\"},{\"num\":12,\"tag\":\" 视频\"},{\"num\":17,\"tag\":\" 购物\"},{\"num\":1,\"tag\":\" 资讯\"},{\"num\":1,\"tag\":\" 运动健身\"},{\"num\":16,\"tag\":\" 阅读\"},{\"num\":1,\"tag\":\" 音乐\"},{\"num\":16,\"tag\":\"IT 科技\"},{\"num\":23,\"tag\":\"交通\"},{\"num\":1,\"tag\":\"休闲、阅读\"},{\"num\":19,\"tag\":\"体育\"},{\"num\":33,\"tag\":\"健康医疗\"},{\"num\":3,\"tag\":\"公益\"},{\"num\":3,\"tag\":\"医疗\"},{\"num\":1,\"tag\":\"商业服务\"},{\"num\":1,\"tag\":\"图片\"},{\"num\":59,\"tag\":\"娱乐\"},{\"num\":11,\"tag\":\"富媒体\"},{\"num\":275,\"tag\":\"工具\"},{\"num\":5,\"tag\":\"房地产\"},{\"num\":35,\"tag\":\"投资理财\"},{\"num\":52,\"tag\":\"教育\"},{\"num\":31,\"tag\":\"新闻\"},{\"num\":7,\"tag\":\"旅游\"},{\"num\":34,\"tag\":\"旅行\"},{\"num\":31,\"tag\":\"查询\"},{\"num\":32,\"tag\":\"汽车\"},{\"num\":1,\"tag\":\"理财\"},{\"num\":127,\"tag\":\"生活\"},{\"num\":16,\"tag\":\"生活服务\"},{\"num\":5,\"tag\":\"电台\"},{\"num\":2,\"tag\":\"电商\"},{\"num\":1,\"tag\":\"电影\"},{\"num\":7,\"tag\":\"社交\"},{\"num\":27,\"tag\":\"社区\"},{\"num\":19,\"tag\":\"美图\"},{\"num\":1,\"tag\":\"美图.工具\"},{\"num\":10,\"tag\":\"美妆\"},{\"num\":21,\"tag\":\"美食\"},{\"num\":30,\"tag\":\"自媒体\"},{\"num\":5,\"tag\":\"视频\"},{\"num\":55,\"tag\":\"购物\"},{\"num\":1,\"tag\":\"运动健身\"},{\"num\":1,\"tag\":\"金融\"},{\"num\":31,\"tag\":\"阅读\"}]";
        return json;
    }

    /**
     * ajax请求
     *
     * @param modelMap
     * @param liebaoApp
     * @param request
     * @return
     */
    @RequestMapping(value = "getData", method = RequestMethod.GET)
    @ResponseBody
    public PageInfo<LiebaoApp> getData(ModelMap modelMap, LiebaoApp liebaoApp, HttpServletRequest request) {
        PageParam pageParam = this.getPageParam(request);
        liebaoApp.setIsCheck(IConstInfo.CHECKED);
        PageInfo<LiebaoApp> liebaoAppPageInfo = liebaoAppService.getListByPage(liebaoApp, pageParam);
        modelMap.addAttribute("liebaoAppList", liebaoAppPageInfo);
        modelMap.addAttribute("liebaoApp", liebaoApp);
        return liebaoAppPageInfo;
    }

    /**
     * 详细页
     *
     * @param modelMap
     * @param id
     * @return
     */
    @RequestMapping(value = "/app/{id}", method = RequestMethod.GET)
    public String wxAppDetail(@PathVariable Integer id, ModelMap modelMap) {
        LiebaoApp liebaoApp = liebaoAppService.selectByPrimaryKey(id);
        modelMap.addAttribute("liebaoApp", liebaoApp);
        modelMap.addAttribute("categoryName", CategoryType.getName(liebaoApp.getCategory()));
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        modelMap.addAttribute("seoTitle", liebaoApp.getAppName() + " - " + liebaoApp.getAppName() + "小程序" + " - " + liebaoApp.getAppName() + "二维码" + " - " + "小程序大全");
        modelMap.addAttribute("seoKeywords", liebaoApp.getAppName() + "," + liebaoApp.getAppName() + "小程序" + "," + liebaoApp.getAppName() + "二维码");
        String seoDescription = liebaoApp.getAppSum();
        if (StringUntils.isEmpty(liebaoApp.getAppSum())) {
            seoDescription = liebaoApp.getAppName() + "," + liebaoApp.getAppName() + "小程序" + "," + liebaoApp.getAppName() + "二维码";
        }
        modelMap.addAttribute("seoDescription", seoDescription);
        if(id.equals(89)||id.equals(372)||id.equals(1859)||id.equals(1932)||id.equals(11433)||id.equals(11491)){
            modelMap.addAttribute("liebaoApp", liebaoApp);
            modelMap.addAttribute("categoryName", CategoryType.getName(liebaoApp.getCategory()));
            //seo
            modelMap.addAttribute("seoTitle", liebaoApp.getAppName() + "APP下载 - " + liebaoApp.getAppName() + "小程序" + " - " + liebaoApp.getAppName() + "二维码" );
            modelMap.addAttribute("seoKeywords", liebaoApp.getAppName() + "," + liebaoApp.getAppName() + "APP下载" + "," + liebaoApp.getAppName() + "二维码");
            modelMap.addAttribute("seoDescription", liebaoApp.getAppName() + "APP下载" +seoDescription);
        }
        //热门推荐8
//        LiebaoApp liebaoApp1 = new LiebaoApp();
//        liebaoApp1.setIsCheck(IConstInfo.CHECKED);
//        liebaoApp1.setHomeType(1);
//        List<LiebaoApp> rmtjList = liebaoAppService.searchApp(liebaoApp1, "rmtj");
//        //精挑细选8
//        liebaoApp1.setHomeType(2);
//        List<LiebaoApp> jtxxList = liebaoAppService.searchApp(liebaoApp1, "jtxx");
//        //社交娱乐16
//        liebaoApp1.setHomeType(8);
//        List<LiebaoApp> sjcxList = liebaoAppService.searchApp(liebaoApp1, "sjcx");

        int max = 10000, min = 1;
        int ran1 = (int) (Math.random() * (max - min) + min);
        List<LiebaoApp> rmtjList = liebaoAppMapper.getListFromTo(ran1, 10);
        int ran2 = (int) (Math.random() * (max - min) + min);
        List<LiebaoApp> jtxxList = liebaoAppMapper.getListFromTo(ran2, 10);
        int ran3 = (int) (Math.random() * (max - min) + min);
        List<LiebaoApp> sjcxList = liebaoAppMapper.getListFromTo(ran3, 10);
        modelMap.addAttribute("rmtjList", rmtjList);
        modelMap.addAttribute("jtxxList", jtxxList);
        modelMap.addAttribute("sjcxList", sjcxList);
        if(id.equals(89)||id.equals(372)||id.equals(1859)||id.equals(1932)||id.equals(11433)||id.equals(11491)){
            return  "app/appdidi";
        }else {
            return "app/app";
        }
    }

    /**
     * 文章详情
     *
     * @return
     */
    @RequestMapping(value = "topic/{topicId}")
    public String topic(ModelMap modelMap, @PathVariable Integer topicId) {
        String seoTitle = "";
        String seoKeywords = "";
        String seoDescription = "";
        if (topicId.equals(1001)) {
            seoTitle = "微信小程序大全之微信小程序有哪些 - 好玩的小程序推荐 - 微信小程序大全";
            seoKeywords = "微信小程序有哪些";
            seoDescription = "微信小程序大全之微信小程序有哪些";
        } else if (topicId.equals(1002)) {
            seoTitle = "微信小程序大全之如何申请小程序 - 微信小程序申请指南 - 微信小程序大全";
            seoKeywords = "微信小程序申请指南";
            seoDescription = "微信小程序申请指南";
        } else if (topicId.equals(1003)) {
            seoTitle = "微信小程序大全之腾讯介入新零售？小程序打通最后一环 - 微信小程序大全";
            seoKeywords = "腾讯介入新零售？小程序打通最后一环";
            seoDescription = "微信小程序大全之腾讯介入新零售？小程序打通最后一环";
        } else if (topicId.equals(1004)) {
            seoTitle = "微信小程序大全之微信商品搜索，打造电商入口？ - 微信小程序大全";
            seoKeywords = "微信商品搜索，打造电商入口？";
            seoDescription = "微信小程序大全之微信商品搜索，打造电商入口？";
        } else if (topicId.equals(1005)) {
            seoTitle = "微信小程序大全之微信小程序能否干掉APP - 微信小程序大全";
            seoKeywords = "微信小程序能否干掉APP";
            seoDescription = "微信小程序大全之微信小程序能否干掉APP";
        } else if (topicId.equals(1006)) {
            seoTitle = "微信小程序大全之小程序新增功能，能用小程序打开小程序 - 微信小程序大全";
            seoKeywords = "小程序新增功能，能用小程序打开小程序";
            seoDescription = "微信小程序大全之小程序新增功能，能用小程序打开小程序";
        } else if (topicId.equals(1007)) {
            seoTitle = "微信小程序大全之微信小程序在不同领域的玩法 - 微信小程序大全";
            seoKeywords = "微信小程序大全之微信小程序在不同领域的玩法";
            seoDescription = "微信小程序大全之微信小程序在不同领域的玩法";
        }
        //seo
        modelMap.addAttribute("seoTitle", seoTitle);
        modelMap.addAttribute("seoKeywords", seoKeywords);
        modelMap.addAttribute("seoDescription", seoDescription);
        //热门推荐8
        LiebaoApp liebaoApp = new LiebaoApp();
        liebaoApp.setIsCheck(IConstInfo.CHECKED);
        liebaoApp.setHomeType(1);
        List<LiebaoApp> rmtjList = liebaoAppService.searchApp(liebaoApp, "rmtj");
        //精挑细选8
        liebaoApp.setHomeType(2);
        List<LiebaoApp> jtxxList = liebaoAppService.searchApp(liebaoApp, "jtxx");
        //社交娱乐16
        liebaoApp.setHomeType(8);
        List<LiebaoApp> sjcxList = liebaoAppService.searchApp(liebaoApp, "sjcx");
        modelMap.addAttribute("rmtjList", rmtjList);
        modelMap.addAttribute("jtxxList", jtxxList);
        modelMap.addAttribute("sjcxList", sjcxList);
        return "app/topic";
    }

    @RequestMapping("/jsonToClass")
    @ResponseBody
    public String jsonToClass(HttpServletRequest request) {
        String jsonStr = request.getParameter("jsonStr");
        try {
            List<LiebaoApp> liebaoJsonPojoList = new ArrayList<>();
            List liebaoJsonPojoListStr = JsonUtil.json2Obj(jsonStr, List.class);
            for (Object map : liebaoJsonPojoListStr) {
                LiebaoApp liebaoJsonPojo = JsonUtil.json2Obj(JsonUtil.obj2Json(map), LiebaoApp.class);
                liebaoJsonPojoList.add(liebaoJsonPojo);
            }
            liebaoAppService.saveAppList(liebaoJsonPojoList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    @RequestMapping("/jsonToClass_zhixiao")
    @ResponseBody
    public String jsonToClass_zhixiao(HttpServletRequest request) {
//        String jsonStr = request.getParameter("jsonStr");
        String jsonStr = HttpClientUtil.doGet("https://minapp.com/api/v5/trochili/miniapp/?limit=21");
        JSONObject jsonObject = (JSONObject) JSONObject.parse(jsonStr);
        String limit = ((JSONObject) JSONObject.parse(jsonObject.getString("meta"))).getString("limit");
        JSONArray jsonArray = JSONArray.parseArray(jsonObject.getString("objects"));

        List<LiebaoApp> liebaoJsonPojoList = new ArrayList<>();
        LiebaoApp liebao;
        for (int i = 0; i < jsonArray.size(); i++) {
            liebao = new LiebaoApp();
            JSONObject obj = (JSONObject) jsonArray.get(i);
            liebao.setAppId(Integer.parseInt(obj.getString("id")));
            liebao.setAppId(Integer.parseInt(obj.getString("id")));
            liebao.setAppSum(obj.getString("description"));
            liebao.setAppName(obj.getString("name"));
            liebao.setAuthor("酷酷屋小程序");
            liebao.setHot(obj.getString("visit_amount"));
            liebao.setLogoUrl(((JSONObject) JSONObject.parse(obj.getString("icon"))).getString("image"));
            liebao.setQrUrl(((JSONObject) JSONObject.parse(obj.getString("qrcode"))).getString("image"));
            JSONArray screenshotArr = JSONArray.parseArray(obj.getString("screenshot"));
            String shotStr = "";
            for (int j = 0; j < screenshotArr.size(); j++) {
                JSONObject shotObj = (JSONObject) screenshotArr.get(j);
                shotStr += shotObj.getString("image") + ",";
            }
            liebao.setScrUrlsArr(shotStr.substring(0, shotStr.length() - 1));

            JSONArray tagArr = JSONArray.parseArray(obj.getString("tag"));
            String tagStr = "";
            for (int k = 0; k < tagArr.size(); k++) {
                JSONObject tagObj = (JSONObject) tagArr.get(k);
                tagStr += tagObj.getString("name") + ",";
            }
            liebao.setTagsArr(tagStr.substring(0, tagStr.length() - 1));
            liebao.setSourceId(2);
            liebao.setSourceUrl("minapp.com");
            liebao.setHomeType(3);
            liebaoJsonPojoList.add(liebao);
        }
        liebaoAppService.saveAppList(liebaoJsonPojoList);
        return "";
    }

    @RequestMapping(value = "kuaixun/{pageNume}", method = RequestMethod.GET)
    public String kuaixun(ModelMap modelMap, Kuaixun kuaixun, @PathVariable int pageNume, HttpServletRequest request) {
        PageParam pageParam = this.getPageParam(request);
        pageParam.setPageNum(pageNume);
        PageInfo<Kuaixun> pageInfo = kuaixunService.getListByPage(kuaixun, pageParam);
        modelMap.addAttribute("pageInfo", pageInfo);
        modelMap.addAttribute("pageParam", pageParam);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        if (pageNume == 1) {
            modelMap.addAttribute("seoTitle", "酷酷屋小程序行业快讯 - www.kukuwu.com");
            modelMap.addAttribute("seoKeywords", "小程序行业 ,小程序快讯,小程序动态");
            modelMap.addAttribute("seoDescription", "小程序行业快讯及最新动态");
        } else {
            String tile = pageInfo.getList().get(0).getTitle();
            modelMap.addAttribute("seoTitle", tile + " - www.kukuwu.com");
            modelMap.addAttribute("seoKeywords", "最新动态,快讯," + tile);
            modelMap.addAttribute("seoDescription", "小程序最新动态：" + tile);
        }
        return "app/kauixun";
    }

    /**
     * 快讯详细页
     *
     * @param modelMap
     * @param id
     * @return
     */
    @RequestMapping(value = "/infoDetail/{id}", method = RequestMethod.GET)
    public String infoDetail(@PathVariable Long id, ModelMap modelMap) {
        Kuaixun kuaixun = kuaixunMapper.selectByPrimaryKey(id);
        modelMap.addAttribute("data", kuaixun);
        //seo
        modelMap.addAttribute("seoTitle", kuaixun.getTitle() + " - " + "酷酷屋小程序");
        modelMap.addAttribute("seoKeywords", kuaixun.getTitle());
        modelMap.addAttribute("seoDescription", kuaixun.getTitle() + "最新资讯");
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        int max = 10000, min = 1;
        int ran1 = (int) (Math.random() * (max - min) + min);
        List<LiebaoApp> rmtjList = liebaoAppMapper.getListFromTo(ran1, 10);
        int ran2 = (int) (Math.random() * (max - min) + min);
        List<LiebaoApp> jtxxList = liebaoAppMapper.getListFromTo(ran2, 10);
        int ran3 = (int) (Math.random() * (max - min) + min);
        List<LiebaoApp> sjcxList = liebaoAppMapper.getListFromTo(ran3, 10);
        modelMap.addAttribute("rmtjList", rmtjList);
        modelMap.addAttribute("jtxxList", jtxxList);
        modelMap.addAttribute("sjcxList", sjcxList);
        return "app/infoDetail";
    }

    @RequestMapping(value = "dayPhb", method = RequestMethod.GET)
    public String kuaixun(ModelMap modelMap, HttpServletRequest request) {
//        PageParam pageParam = this.getPageParam(request);
//        pageParam.setPageNum(pageNume);
//        PageInfo<Kuaixun> pageInfo = kuaixunService.getListByPage(kuaixun, pageParam);
//        modelMap.addAttribute("pageInfo", pageInfo);
//        modelMap.addAttribute("pageParam", pageParam);
//        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        modelMap.addAttribute("seoTitle", "小程序行业快讯 - www.kukuwu.com");
        modelMap.addAttribute("seoKeywords", "小程序行业 ,小程序快讯,小程序动态");
        modelMap.addAttribute("seoDescription", "小程序行业快讯及最新动态");
        return "app/dayPhb";
    }


    /**
     * APP推荐
     * @param modelMap
     * @param appso
     * @param pageNume
     * @param request
     * @return
     */
    @RequestMapping(value = "appTuiJian/{pageNume}", method = RequestMethod.GET)
    public String appTuiJian(ModelMap modelMap, Appso appso, @PathVariable int pageNume, HttpServletRequest request) {
        PageParam pageParam = this.getPageParam(request);
        pageParam.setPageNum(pageNume);
        PageInfo<Appso> pageInfo = kuaixunService.getAppListByPage(appso, pageParam);
        modelMap.addAttribute("pageInfo", pageInfo);
        modelMap.addAttribute("pageParam", pageParam);
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        //seo
        modelMap.addAttribute("seoTitle", "app推荐 - www.kukuwu.com");
        modelMap.addAttribute("seoKeywords", "app推荐");
        modelMap.addAttribute("seoDescription", "好玩的app推荐");

        return "app/appTuiJian";
    }


    /**
     * APP推荐详情
     *
     * @param modelMap
     * @param id
     * @return
     */
    @RequestMapping(value = "/appTuiJianDetail/{id}", method = RequestMethod.GET)
    public String appTuiJianDetail(@PathVariable Long id, ModelMap modelMap) {
        Appso appso = appsoMapper.selectByPrimaryKey(id);
        appso.setPost_content(appso.getPost_content().replaceAll("APPSO","https://www.kukuwu.com/"));
        modelMap.addAttribute("data", appso);
        //seo
        modelMap.addAttribute("seoTitle", appso.getPost_title() + " - " + "酷酷屋小程序");
        modelMap.addAttribute("seoKeywords", arrayToStr(appso.getPost_tag()));
        modelMap.addAttribute("seoDescription", appso.getPost_excerpt());
        modelMap.addAttribute("imgServer", IConstInfo.imgServer);
        int max = 10000, min = 1;
        int ran1 = (int) (Math.random() * (max - min) + min);
        List<LiebaoApp> rmtjList = liebaoAppMapper.getListFromTo(ran1, 10);
        int ran2 = (int) (Math.random() * (max - min) + min);
        List<LiebaoApp> jtxxList = liebaoAppMapper.getListFromTo(ran2, 10);
        int ran3 = (int) (Math.random() * (max - min) + min);
        List<LiebaoApp> sjcxList = liebaoAppMapper.getListFromTo(ran3, 10);
        modelMap.addAttribute("rmtjList", rmtjList);
        modelMap.addAttribute("jtxxList", jtxxList);
        modelMap.addAttribute("sjcxList", sjcxList);
        return "app/appTuiJianDetail";
    }


    private String arrayToStr (String str){
        String rel = "";
        if(!StringUntils.isEmpty(str)){
            JSONArray array= JSONArray.parseArray(str);
            for (Object obj:array) {
                if(!StringUntils.isEmpty(obj.toString())){
                    rel += obj.toString() + "，";
                }
            }
            return rel;
        }
        return "微信小程序";
    }

    public static void main(String[] args) {
        String ss= "[\"RTA\",\"极限通关\",\"游戏\"]";
        JSONArray array= JSONArray.parseArray(ss);
        String a1 = array.get(0).toString();
        String a2 = array.get(1).toString();

    }

}
